package com.bristua.mall.user.biz;

import com.bristua.mall.common.biz.QueryDictionaryBiz;
import com.bristua.mall.common.constant.Constant;
import com.bristua.mall.common.model.TDictionary;
import com.bristua.mall.common.utils.CacheUtil;
import com.bristua.mall.common.utils.DateUtil;
import com.bristua.mall.common.utils.SequenceUtil;
import com.bristua.mall.user.dao.TUserChargeMapper;
import com.bristua.mall.user.model.TUser;
import com.bristua.mall.user.model.TUserCharge;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2019/5/14.
 */
@Service
@Transactional
public class UserChargeVipBiz {
    @Autowired
    private CacheUtil cacheUtil;

    @Autowired
    private QueryDictionaryBiz queryDictionaryBiz;

    @Resource
    private TUserChargeMapper tUserChargeMapper;

    public Map<String,Object> userChargeVip(String chargeType){
        List<TDictionary> tDictionaries = queryDictionaryBiz.queryDictionary(Constant.VIP_AMT);
        if(tDictionaries!=null && tDictionaries.size()>0){
            TUser userSession = (TUser)cacheUtil.getUserSession();
            TUserCharge tUserCharge = new TUserCharge();
            tUserCharge.setChargeAmount(tDictionaries.get(0).getDictionaryValue());
            tUserCharge.setChargeId(SequenceUtil.nextId());
            tUserCharge.setChargeType(chargeType);
            tUserCharge.setCreateTime(DateUtil.getDateTime3());
            tUserCharge.setStatus("0");
            tUserCharge.setUserId(userSession.getUserId());
            tUserChargeMapper.insert(tUserCharge);
            Map<String,Object> result = new HashMap();
            result.put("orderId",tUserCharge.getChargeId());
            return result;
        }
        return null;
    }
}
